package com.mfl.controller.admin;

import com.mfl.common.PageResult;
import com.mfl.common.Result;
import com.mfl.pojo.dto.BannerDTO;
import com.mfl.pojo.dto.BannerPageQueryDTO;
import com.mfl.pojo.vo.BannerPageQueryVO;
import com.mfl.service.BannerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/cky/admin/banner")
@Slf4j
public class BannerController {

    @Autowired
    private BannerService bannerService;

    /**
     * 分页查询轮播图
     * @param bannerPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> page(BannerPageQueryDTO bannerPageQueryDTO){
        log.info("分页查询轮播图：{}", bannerPageQueryDTO);
        PageResult pageResult = bannerService.pageQuery(bannerPageQueryDTO);
        return Result.success("", pageResult);
    }

    /**
     * 新增轮播图
     * @param bannerDTO
     * @return
     */
    @PostMapping("/insert")
    public Result insert(@RequestBody BannerDTO bannerDTO){
        log.info("新增轮播图：{}", bannerDTO);
        bannerService.insert(bannerDTO);
        return Result.success("新增成功");
    }

    /**
     * 批量删除轮播图
     * @param ids
     * @return
     */
    @DeleteMapping("/batchDelete")
    public Result batchDelete(@RequestParam List<Integer> ids){
        log.info("批量删除轮播图：{}", ids);
        bannerService.batchDelete(ids);
        return Result.success("删除成功");
    }

    /**
     * 修改轮播图状态
     * @return
     */
    @PutMapping("/status/{status}")
    public Result updateStatus(@PathVariable Integer status, @RequestBody Map<String, Object> requestBody) {
        Integer id = (Integer) requestBody.get("id");
        log.info("修改轮播图状态：id：{}, status：{}", id, status);
        bannerService.updateStatus(status, id);
        return Result.success("修改成功");
    }
}
